lib/repo: Add commit version metadata to summary metadata
authorDan Nicholson <dbn@endlessos.org>
Fri, 4 Feb 2022 21:11:06 +0000 (14:11 -0700)
committerDan Nicholson <dbn@endlessos.org>
Fri, 4 Feb 2022 21:28:11 +0000 (14:28 -0700)
The commit metadata `version` key is well established but getting it for
a remote commit is cumbersome since the commit object needs to be
fetched and loaded. Including it in the summary additional metadata
allows a much more convenient view of what each of the remote refs
represents.

man/ostree-summary.xml
src/libostree/ostree-core.h
src/libostree/ostree-repo-private.h
src/libostree/ostree-repo.c
src/ostree/ot-dump.c
tests/test-summary-view.sh

index 4c9652ccb47bfea759366668be100461a1ed1c0c..e853e8cdf957c828843f51147940372042bccfe4 100644 (file)
@@ -183,6 +183,7 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
     Latest Commit (4.2 MB):
       9828ab80f357459b4ab50f0629beab2ae3b67318fc3d161d10a89fae353afa90
     Timestamp (ostree.commit.timestamp): 2017-11-21T01:41:10-08
+    Version (ostree.commit.version): 1.2.3
 
 Last-Modified (ostree.summary.last-modified): 2018-01-12T22:06:38-08
 </programlisting>
index 36e6129090171d18b56f929abbcb2a98c0b2ca34..48a75f92a5359cf9224c0c0a63b1b3927a77e0ce 100644 (file)
@@ -164,6 +164,8 @@ typedef enum {
  * The currently defined keys for the `a{sv}` of additional metadata for each commit are:
  *  - key: `ostree.commit.timestamp`, value: `t`, timestamp (seconds since the
  *    Unix epoch in UTC, big-endian) when the commit was committed
+ *  - key: `ostree.commit.version`, value: `s`, the `version` value from the
+ *    commit's metadata if it was defined. Since: 2022.2
  */
 #define OSTREE_SUMMARY_GVARIANT_STRING "(a(s(taya{sv}))a{sv})"
 #define OSTREE_SUMMARY_GVARIANT_FORMAT G_VARIANT_TYPE (OSTREE_SUMMARY_GVARIANT_STRING)
index 6d8f0193bce6e6b5b0523f4826d2915b27bf5947..988c2179af3927447b95f34dae16d7d5cdb8b380 100644 (file)
@@ -63,6 +63,7 @@ G_BEGIN_DECLS
 /* Well-known keys for the additional metadata field in a commit in a ref entry
  * in a summary file. */
 #define OSTREE_COMMIT_TIMESTAMP "ostree.commit.timestamp"
+#define OSTREE_COMMIT_VERSION "ostree.commit.version"
 
 typedef enum {
   OSTREE_REPO_TEST_ERROR_PRE_COMMIT = (1 << 0),
index 64a8fea92d177417c3cee8674819217495c25366..6c541029dd6c365a8e5e83c021cd19efd1b5259c 100644 (file)
@@ -6067,10 +6067,11 @@ summary_add_ref_entry (OstreeRepo       *self,
   g_autoptr(GVariant) commit_obj = NULL;
   if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, checksum, &commit_obj, error))
     return FALSE;
+  g_autoptr(GVariant) orig_metadata = g_variant_get_child_value (commit_obj, 0);
 
   g_variant_dict_init (&commit_metadata_builder, NULL);
 
-  /* Forward the commit’s timestamp if it’s valid. */
+  /* Forward the commit’s timestamp and version if they're valid. */
   guint64 commit_timestamp = ostree_commit_get_timestamp (commit_obj);
   g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (commit_timestamp);
 
@@ -6078,6 +6079,10 @@ summary_add_ref_entry (OstreeRepo       *self,
     g_variant_dict_insert_value (&commit_metadata_builder, OSTREE_COMMIT_TIMESTAMP,
                                  g_variant_new_uint64 (GUINT64_TO_BE (commit_timestamp)));
 
+  const char *version = NULL;
+  if (g_variant_lookup (orig_metadata, OSTREE_COMMIT_META_KEY_VERSION, "&s", &version))
+    g_variant_dict_insert (&commit_metadata_builder, OSTREE_COMMIT_VERSION, "s", version);
+
   g_variant_builder_add_value (refs_builder,
                                g_variant_new ("(s(t@ay@a{sv}))", ref,
                                               (guint64) g_variant_get_size (commit_obj),
index b874db0fef1c79172bc38e9a568d62cca00db4e8..509eb792d114f8431d6bfe5a5eb857ba4fd7aaeb 100644 (file)
@@ -249,6 +249,11 @@ dump_summary_ref (const char   *collection_id,
           pretty_key = "Timestamp";
           value_str = uint64_secs_to_iso8601 (GUINT64_FROM_BE (g_variant_get_uint64 (value)));
         }
+      else if (g_strcmp0 (key, OSTREE_COMMIT_VERSION) == 0)
+        {
+          pretty_key = "Version";
+          value_str = g_strdup (g_variant_get_string (value, NULL));
+        }
       else
         {
           value_str = g_variant_print (value, FALSE);
index 088628d8a387c9f87b859591ceac0a362acc14ef..9dfc74f44689b8b23d9121627a3564a2acbe400c 100755 (executable)
@@ -56,6 +56,7 @@ assert_file_has_content_literal summary.txt "* main"
 assert_file_has_content_literal summary.txt "* other"
 assert_file_has_content_literal summary.txt "ostree.summary.last-modified"
 assert_file_has_content_literal summary.txt "Timestamp (ostree.commit.timestamp): "
+assert_file_has_content_literal summary.txt "Version (ostree.commit.version): 3.2"
 echo "ok view summary"
 
 # Check the summary can be viewed raw too.